package user_assets_usdt

import (
	"context"
	"strconv"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUsdtWalletInsertInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 添加
func NewUserUsdtWalletInsertInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUsdtWalletInsertInfoLogic {
	return &UserUsdtWalletInsertInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUsdtWalletInsertInfoLogic) UserUsdtWalletInsertInfo(req *types.UserUSDTWalletsInfoRequest) (resp *types.UserUSDTWalletInsertInfoResponse, err error) {
	var usdtType string
	if req.UsdtType == 0 {
		usdtType = ""
	} else {
		usdtType = strconv.FormatInt(req.UsdtType, 10)
	}
	_, err = l.svcCtx.AssetsRpc.UserChannel.UserUsdtWalletsInsert(l.ctx, &rpc.UserUsdtWalletsInsertRequest{
		UserId:   req.UserID,
		UsdtType: usdtType,
		Address:  req.Address,
	})

	if err != nil {
		return &types.UserUSDTWalletInsertInfoResponse{
			IsInsert: false,
		}, err
	}
	return &types.UserUSDTWalletInsertInfoResponse{
		IsInsert: true,
	}, err
}
